package com.zretc.kscxmz.controller;

import com.zretc.kscxmz.entity.Menu;
import com.zretc.kscxmz.services.MenuService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/Menu")
public class MenuController {

    private Logger logger = LoggerFactory.getLogger(MenuController.class);
    @Autowired
    private MenuService menuService;

    @RequestMapping("/rootMenu")//一级菜单
    @ResponseBody
    public List<Menu> getRootMenu(){
        List<Menu> rootMenu = menuService.getRootMenu();
        return rootMenu;
    }

    @RequestMapping("/subMenu")
    @ResponseBody
    public List<Menu> getSubMenu(@RequestParam("parentId") String parentId,
                                 @RequestParam("roleId") String roleId){

        List<Menu> subMenu = menuService.getSubMenuByParentId(Integer.parseInt(parentId),Integer.parseInt(roleId));

        logger.info("================"+subMenu.toString());
        return subMenu;
    }
    @RequestMapping("/allMenu")
    @ResponseBody
    public List<Menu> getAllPowerMenu(@RequestParam("roleId") String roleId){
        List<Menu> rolePowers = menuService.getMenuByRoleId(Integer.parseInt(roleId));
        return rolePowers;
    }
    @RequestMapping("/updateMenu")
    @ResponseBody
    public int updatePowerMenu(@RequestBody List<String> list,
                                      @RequestParam("roleId") String roleId,
                                      @RequestParam("showStatus") String showStatus){
        int i = menuService.modifyShowStatusByMenuId(list, Integer.parseInt(roleId), Integer.parseInt(showStatus));
        logger.info("======="+i+"++++++++++");
        return i;
    }
}
